<template>
<h2>会员信息列表</h2>
会员名称<input type="text" v-model="chaxun.mname"/>
手机号<input type="text" v-model="chaxun.phone"/>
<input type="button" value="查询" class="btn btn-success" @click="Show" />
<input type="button" value="导出数据" class="btn btn-info" @click="Exportfile" />

<table class="table table-bordered">
    <thead>
        <tr class="bg-info">
            <td>会员名称</td>
            <td>手机号码</td>
            <td>可用余额</td>
            <td>可用积分</td>
            <td>操作</td>
        </tr>
    </thead>
    <tbody>
        <tr v-for="item in info">
            <td>{{ item.mname }}</td>
            <td>{{ item.phone }}</td>
            <td>{{ item.ymoney }}</td>
            <td>{{ item.jifen }}</td>
            <td>
                <a href="#" @click="Xqing(item.mid)" style="margin-right: 10px;">详情</a>
                <a href="#" @click="Updjifen(item.mid)" style="margin-right: 10px;">修改积分</a>
                <a href="#" @click="Chongzhi(item.mid)" style="margin-right: 10px;">充值</a>
            </td>
        </tr>
    </tbody>
</table>
</template>
<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router';
const router=useRouter()

const info=ref([{
    mid:0,
    mname:'',
    phone:'',
    sex:'男',
    birenday:'',
    ymoney:0,
    jifen:0,
    image:''
}])

onMounted(()=>{
    Show()
})
//查询条件
const chaxun=ref({
    mname:'',
    phone:''
})
//显示
const Show=()=>{
    axios.get('https://localhost:7279/api/Meber/MeberShow',{
        params:{
            mname:chaxun.value.mname,
            phone:chaxun.value.phone
        }
    })
    .then(res=>{
        info.value=res.data
    })
    .catch(err=>{
        console.log(err)
    })
}

//详情
const Xqing=(id:number)=>{
    router.push({
        name:'MeberXqing',
        params:{
            id:id
        }
    })
}
//修改积分
const Updjifen=(id:number)=>{
    router.push({
        name:'MeberUpdjifen',
        params:{
            id:id
        }
    })
}
//充值
const Chongzhi=(id:number)=>{
    router.push({
        name:'MeberChongzhi',
        params:{
            id:id
        }
    })
}
//导出数据
const Exportfile=()=>{
    axios.get('https://localhost:7279/api/Meber/ExportFile',{
        params:{
            pathname:"C:\\Users\\Lenovo\\Desktop\\导出\\会员信息.xlsx"
        }
    })
    .then(res=>{
        if(res.data>0){
            alert('导出成功')
        }
        else{
            alert('导出失败')
        }
    })
}

</script>